package com.jianganming.bridge;

/**
 * 桥接模式
 *不直接调用业务类，通过中间对象去调用各个阶段的具体目标类。
 * 桥接对象公共部分通过父抽象类去做，具体调用业务由桥接对象来调用目标业务方法
 */
public class BridgeTest2 {
    public static void main(String[] args) {
       ICourse course = new JavaCourse();
       course.shangke();
       course = new CppCourse();
       course.shangke();
    }
}

interface ICourse{
    void shangke();

}
interface INote {
    void edit();
}

interface IVideo {
    void play();
}

//桥接模版
abstract class Course implements ICourse{
    private INote note;
    private IVideo video;

    public INote getNote() {
        return note;
    }

    public IVideo getVideo() {
        return video;
    }

    public Course(INote note, IVideo video) {
        this.note = note;
        this.video = video;
    }
    public abstract void shangke();
}

//桥接对象
class JavaCourse extends Course{

    public JavaCourse() {
        super(new JavaNote(), new JavaVideo());
    }

    @Override
    public void shangke() {
        System.out.println("开始上Java课程");
        getNote().edit();
        getVideo().play();
    }
}

//桥接对象
class CppCourse extends Course{

    public CppCourse() {
        super(new CppNote(), new CppVideo());
    }

    @Override
    public void shangke() {
        System.out.println("开始上C++课程");
        getNote().edit();
        getVideo().play();
    }
}


//具体业务
class JavaVideo implements IVideo{

    @Override
    public void play() {
        System.out.println("播放Java视频");
    }
}
//具体业务
class JavaNote implements INote{

    @Override
    public void edit() {
        System.out.println("做java笔记");
    }
}

class CppVideo implements IVideo{

    @Override
    public void play() {
        System.out.println("播放C++视频");
    }
}

class CppNote implements INote{

    @Override
    public void edit() {
        System.out.println("做C++笔记");
    }
}